﻿using FluentNHibernate.Mapping;

namespace NMA.Infrastructure.NHibernate.Mapping
{
    using NMA.Domain.Model;
    using NMA.Infrastructure.NHibernate.DomainObject;

    public class CategoryMap : ClassMap<Category>
    {
        public CategoryMap()
        {
            //LazyLoad();

            Table("[NMA].[dbo].[Category]");
            //ForeignKey.EndsWith("ID");
            Id(x => x.Id, "ID").GeneratedBy.Guid();
            Map(x => x.Name, "Name").Not.Nullable().Length(50);
            Map(x => x.CreatedDate, "CreatedDate").Not.Nullable();
            Map(x => x.UpdatedDate, "UpdatedDate");
            Map(x => x.CreatedUser, "CreatedUser").Not.Nullable().Length(30);
            Map(x => x.UpdatedUser, "UpdatedUser").Length(30);
            HasMany<News>(x => x.News).KeyColumns.Add("Category_Id")
                .AsList()
                .Inverse().Cascade.All();
        }
    }
}
